document.addEventListener("DOMContentLoaded", function() {
  // 获取相关元素
  const payButton = document.querySelector('.pay');
  const payModal = document.getElementById('payModal');
  const closeModal = document.getElementsByClassName('close')[0];
  const confirmPayButton = document.getElementById('confirmPay');
  const cancelPayButton = document.getElementById('cancelPay');

  // 显示模态框
  payButton.addEventListener('click', () => {
    payModal.style.display = 'block';
  });

  // 关闭模态框
  closeModal.addEventListener('click', () => {
    payModal.style.display = 'none';
  });
  cancelPayButton.addEventListener('click', () => {
    payModal.style.display = 'none';
  });

  // 阻止点击模态框外部时关闭
  // window.addEventListener('click', (event) => {
  //   if (event.target === payModal) {
  //     payModal.style.display = 'none';
  //   }
  // });

  // 获取car.html传入的money
  let payMoney = JSON.parse(localStorage.getItem('money'));
  console.log(payMoney);

  let html = '';
  html += `应付金额：<span>${payMoney.toFixed(2)}</span>`;
  document.querySelector('.main-msg-3').innerHTML = html;

  let html1 = '';
  html1 += `支付金额：<span>${payMoney.toFixed(2)}</span>`;
  document.querySelector('.main-msg-8').innerHTML = html1;

  // 添加确认支付按钮的点击事件监听器
  cancelPayButton.addEventListener('click', function() {
    localStorage.clear(); // 清除localStorage数据
    window.location.href = 'http://127.0.0.1:5501/car.html';

    payModal.style.display = 'none'; // 隐藏支付弹窗
  });
});
// 页面跳转
let navLogin = document.querySelector('.nav-login');
let navRegist = document.querySelector('.nav-regist');

navLogin.addEventListener('click',function(){
  window.location.href = '/login.html';
});
navRegist.addEventListener('click',function(){
  window.location.href = '/register.html';
});